package org.dream.ui.chart.industry;

import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashSet;
import java.util.Set;

import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JPanel;

import org.dream.service.StockService;
import org.dream.service.StockServiceImpl;
import org.dream.ui.MainFrame;

/**
 * 显示设置对话框
 * 
 * @author qiuriyuchen E-mail:panpan_001@126.com
 */
public class IndustrySetDialog extends JDialog {
	private StockService stockService = new StockServiceImpl();
	private IndustryChartBuilder builder;

	public IndustrySetDialog(Frame owner, boolean modal, int x, int y, IndustryChartBuilder builder) {
		super(owner, null, modal);
		this.builder = builder;
		this.setContentPane(new ViewSetPanel());
		this.setLocation(x, y);
		this.setSize(600, 400);
		this.setVisible(true);

	}

	public void repaintPriceChart() {
	}

	class ViewSetPanel extends JPanel {
		Set<JCheckBox> boxs = new HashSet<JCheckBox>();

		public ViewSetPanel() {
			this.setLayout(new FlowLayout());
			// K线
			for (String string : builder.industryMap.keySet()) {
				JCheckBox checkBox = new JCheckBox(string);
				checkBox.addActionListener(new CheckActionListener());
				boxs.add(checkBox);
				this.add(checkBox);
			}
		}

		class CheckActionListener implements ActionListener {
			public void actionPerformed(ActionEvent e) {
				Set<String> keys = new HashSet<String>();
				for (JCheckBox box : boxs) {
					if (box.isSelected()) {
						keys.add(box.getText());
					}
				}
				MainFrame.getInstanse().setCenterPanel(
						builder.buildIndustryChart(keys, builder.calculate));

			}

		}

	}
}
